package com.quasar.hpatient.glide;

import android.content.Context;
import android.util.Log;

import com.bumptech.glide.Glide;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.Registry;
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool;
import com.bumptech.glide.load.engine.cache.LruResourceCache;
import com.bumptech.glide.module.AppGlideModule;

import lib.quasar.context.BaseConstant;

/**
 * description: Glide外部缓存路径
 * created by kalu on 2016/10/24 15:27
 */
@GlideModule
public class GlideDiskModule extends AppGlideModule {

    @Override
    public void applyOptions(Context context, GlideBuilder builder) {
        super.applyOptions(context, builder);

        builder.setLogLevel(Log.DEBUG);

        int memoryCacheSizeBytes = 1024 * 1024 * 20; // 20mb
        builder.setMemoryCache(new LruResourceCache(memoryCacheSizeBytes));

        int bitmapPoolSizeBytes = 1024 * 1024 * 30; // 30mb
        builder.setBitmapPool(new LruBitmapPool(bitmapPoolSizeBytes));

        int diskCacheSizeBytes = 1024 * 1024 * 1000; // 1000 MB
        builder.setDiskCache(new GlideDiskCache(BaseConstant.CACHE_IMAGE, diskCacheSizeBytes));
    }

    @Override
    public void registerComponents(Context context, Glide glide, Registry registry) {
        super.registerComponents(context, glide, registry);
        // LogUtil.e("glide", "registerComponents ==> 图片已注册");
    }

    @Override
    public boolean isManifestParsingEnabled() {
        return false;
    }
}
